"""Initial

Revision ID: 9f62bcd3f32e
Revises: 
Create Date: 2024-03-27 20:34:33.586971

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '9f62bcd3f32e'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('Groups',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('date_add', sa.DateTime(), nullable=False),
    sa.Column('date_update', sa.DateTime(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('trainer_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['trainer_id'], ['Users.id'], use_alter=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id')
    )
    op.create_table('Roles',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('date_add', sa.DateTime(), nullable=False),
    sa.Column('date_update', sa.DateTime(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('Tasks',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('date_add', sa.DateTime(), nullable=False),
    sa.Column('date_update', sa.DateTime(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id')
    )
    op.create_table('Ranks',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('date_add', sa.DateTime(), nullable=False),
    sa.Column('date_update', sa.DateTime(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('task_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['task_id'], ['Tasks.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id')
    )
    op.create_table('Users',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('date_add', sa.DateTime(), nullable=False),
    sa.Column('date_update', sa.DateTime(), nullable=False),
    sa.Column('email', sa.String(length=254), nullable=False),
    sa.Column('hashed_password', sa.String(length=128), nullable=False),
    sa.Column('is_superuser', sa.Boolean(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('is_verified', sa.Boolean(), nullable=False),
    sa.Column('firstname', sa.String(), nullable=True),
    sa.Column('lastname', sa.String(), nullable=True),
    sa.Column('surname', sa.String(), nullable=True),
    sa.Column('code', sa.Integer(), nullable=True),
    sa.Column('birthday', sa.DateTime(), nullable=True),
    sa.Column('photo', postgresql.BYTEA(), nullable=True),
    sa.Column('role', sa.String(), nullable=True),
    sa.Column('is_man', sa.Boolean(), nullable=False),
    sa.Column('rank_id', sa.Integer(), nullable=True),
    sa.Column('contact', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['rank_id'], ['Ranks.id'], ),
    sa.ForeignKeyConstraint(['role'], ['Roles.name'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id')
    )
    op.create_table('StudentGroups',
    sa.Column('student_id', sa.Integer(), nullable=False),
    sa.Column('group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['group_id'], ['Groups.id'], ),
    sa.ForeignKeyConstraint(['student_id'], ['Users.id'], ),
    sa.PrimaryKeyConstraint('student_id', 'group_id'),
    sa.UniqueConstraint('student_id')
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('StudentGroups')
    op.drop_table('Users')
    op.drop_table('Ranks')
    op.drop_table('Tasks')
    op.drop_table('Roles')
    op.drop_table('Groups')
    # ### end Alembic commands ###
